package com.davidk.survey.server.service;

import java.util.ArrayList;

import com.davidk.survey.server.model.QuestionItem;
import com.davidk.survey.server.model.Survey;

public class SurveyService {

	public static void saveSurvey(Survey survey) {
//		try {
//			Questionnaire q;
//			if (survey.getId() > 0) {
//				q = QuestionnaireDAO.getById(survey.getQuestionnaireId());
//			} else {
//				q = new Questionnaire();
//			} 
//			q.setQuestionIds(new Long[survey.getQuestions().size()]);
//
//			for (int i = 0; i < survey.getQuestions().size(); i++) {
//				QuestionItem qi = survey.getQuestions().get(i);
//				QuestionItemDAO.saveQuestionnaire(qi);
//				q.getQuestionIds()[i] = qi.getId();
//			}
//			
//			QuestionnaireDAO.saveQuestionnaire(q);
//			survey.setQuestionnaireId(q.getId());
//		} catch (DataStoreException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}

	public static Survey getSurvey(long id) {
//		Questionnaire q = QuestionnaireDAO.getById(id);
//		if (q == null)
//			return null;
		Survey ret = new Survey();
//		ret.setQuestionnaireId(id);
//		ArrayList<QuestionItem> items = new ArrayList<QuestionItem>();
//		for (int i = 0; q.getQuestionIds() != null && i < q.getQuestionIds().length; i++) {
//			QuestionItem qi = QuestionItemDAO.getById(q.getQuestionIds()[i]);
//			if (qi != null)
//				items.add(qi);
//		}
//		ret.setQuestions(items);
		return ret;
	}
		
	public static Survey getBlankSurvey() {
		Survey ret = new Survey();
		ArrayList<QuestionItem> items = new ArrayList<QuestionItem>();
		items.add(new QuestionItem());
		items.add(new QuestionItem());
		ret.setQuestions(items);
		return ret;
	}
}
